home *** CD-ROM | disk | FTP | other *** search
-
- Rem UFO Bomber!
- Rem By Richard
-
- Rem Variable Setup
- atkang = 3.1415926 / 4.0
- oldatk = atkang
- xbase = 0
- ybase = 240
- atklngth = 30
- score = 0
- numallowed = 1
- numbullets = 0
- maxbullets = 3
- bulletspd = 10
- ufohere = 0
- ufospeed = 0
- ufodir = 0
- ufox = 0
- ufoy = 0
- bombon = 0
- bombx = 0
- bomby = 0
- bombyp = 0
- ufohit = 0
- endx = cos(atkang)*atklngth + xbase
- endy = ybase - sin(atkang)*atklngth
-
- Rem Set a maximum speed (in frames per second)
- fps = 25
- loopSpeed = 1000/fps
-
- Rem Intstructions
- Cls
- Print "- UFO Bomber -"
- Print
- Print "Your goal is to stop bombardment"
- Print "of Planet Earth. Use the keys A and Z"
- Print "keys to aim your weapon, and the space"
- Print "bar to fire. Good luck!"
- Print
- Input "<Press the Enter or Return key to go on>",a$
- Cls
-
- Rem Load in the sprites
- ufospr = LoadSprite("ufo")
- HideSprite ufospr
- expspr = LoadSprite("Woozy01")
- HideSprite expspr
- SetSprite expspr range 4 to 10
- bombspr = LoadSprite("Woozy01")
- SetSprite bombspr range 0 to 3
- HideSprite bombspr
- hits = 0
-
-
- Rem Set up our arrays, and set up the bullets
- Dim bulleton(maxbullets)
- Dim bulletspr(maxbullets)
- Dim bulletx(maxbullets)
- Dim bullety(maxbullets)
- Dim bulletxp(maxbullets)
- Dim bulletyp(maxbullets)
- for t = 1 to maxbullets
- bulletspr(t) = LoadSprite("bullet")
- bulleton(t) = 0
- next t
-
- Rem Screen Setup
- Cls
- Background "earth"
- SetDrawLayer(TEXT)
- Gosub UpdateCannon
-
- Rem Main Loop!
- Rem Wait for keypresses, while updating the UFO, its bomb,
- Rem and flying bullets.
- while 1
- lastTick = Timer()
- Gosub UpdateUFO
- Gosub UpdateBullets
- if bombon then Gosub UpdateBomb
-
- Rem Handle keypresses for aiming the cannon
- if keydown("A") then
- atkang = atkang + .1
- if atkang > 1.54 then atkang = 1.54
- Gosub UpdateCannon
- Goto SkipRest
- Endif
- if keydown("z") then
- atkang = atkang - .1
- if atkang < .1 then atkang = .1
- Gosub UpdateCannon
- Goto SkipRest
- endif
-
- SkipRest:
- Rem Fire cannon?
- if keydown("space") then Gosub FireCannon
-
- Rem Limit overall execution speed to reasonable maximum
- while Timer()-lastTick < loopSpeed
- wend
-
- wend
- end
-
- Rem If the user moves the turret, play a little sound and redraw it on the screen.
- Rem Note that the cannon uses geometry COSINE and SINE calculations to draw a line
- Rem pointing outwards at an arbritrary angle.
-
- UpdateCannon:
- Sound "tank2"
-
- Rem Erase Old cannon line
- Rem Since we're using the text layer, we can use a -1 color to erase
- Color -1
- Line xbase,ybase+1 to endx,endy+1
- Line xbase,ybase to endx,endy
-
- Rem Draw New cannon line
- Color 5 'Uh..Black?
- endx = cos(atkang)*atklngth + xbase
- endy = ybase - sin(atkang)*atklngth
- Line xbase,ybase+1 to endx,endy+1
- Line xbase,ybase to endx,endy
- return
-
- Rem This routine fires a bullet
- Rem We use COSINE and SINE again to send the bullet out across the screen at a
- Rem certain angle. We do a lot of pre-calculation on the bullet, so that
- Rem the bullet update routine (which is executed very often ) has to do as
- Rem little as possible.
-
- FireCannon:
- if numbullets >= numallowed then return
- numbullets = numbullets + 1
- for t = 1 to maxbullets
- if bulleton(t)=0 then
- Sound "biggun1"
- bulletx(t) = endx
- bullety(t) = endy
- bulletxp(t) = cos(atkang)*bulletspd
- bulletyp(t) = -sin(atkang)*bulletspd
- SetSprite bulletspr(t) to bulletxp(t),bulletyp(t)
- ShowSprite bulletspr(t)
- CycleSprite bulletspr(t)
- bulleton(t) = 1
- t = maxbullets
- endif
- next t
- return
-
- Rem Update bullets
- UpdateBullets:
- for t = 1 to maxbullets
- if bulleton(t) then
- bulletx(t) = bulletx(t) + bulletxp(t)
- bullety(t) = bullety(t) + bulletyp(t)
- Rem Simulate a little gravity on the bullet
- bulletyp(t) = bulletyp(t) + .1
- Rem Is bullet still valid?
- if bulletx(t) > 320 or bullety(t) < 0 then
- bulleton(t) = 0
- HideSprite bulletspr(t)
- numbullets = numbullets - 1
- else
- SetSprite bulletspr(t) to bulletx(t),bullety(t)
-
- Rem Now check for a collision with a bomb sprite
- if bombon then
- if SpriteHitSprite(bombspr,bulletspr(t)) then
- score = score + (bombyp * 200)
- Sound "boing1"
- bombon = 0
- HideSprite bombspr
- numbullets = numbullets - 1
- HideSprite bulletSpr(t)
- bulleton(t) = 0
- endif
- endif
- Rem if theres a ufo on the screen, check to see if we hit it and if so,
- Rem destroy it.
- if ufohere and ufohit = 0 then
- if SpriteHitSprite(ufospr,bulletspr(t)) then
- score = score + (ufospd * 20)
- Sound "exp_big"
- HideSprite bulletspr(t)
- bulleton(t) = 0
- numbullets = numbullets - 1
-
- Rem Upgrade players capabilities
- hits = hits + 1
- if hits = 10 then
- bulletspd = 14
- endif
- if hits = 15 then
- numallowed = 2
- bulletspd = 16
- endif
- if hits = 20 then
- bulletspd = 18
- endif
- if hits = 25 then
- numallowed = 3
- endif
-
- ufohit = 25
- HideSprite ufospr
- SetSprite expspr to ufox,ufoy
- CycleSprite expspr
- endif
- endif
- endif
- endif
- next t
- return
-
- Rem Update ufo sprite
- UpdateUFO:
- if ufohere = 0 then
- if random(1,1000) > 25 then
- return
- else
- Sound "whizby"
- ufohere = 1
- TextColor -1
- ufox = 0
- ufoy = random(20,160)
- ufospd = random(2,4) + (hits / 5)
- CycleSprite ufospr
- endif
- else
- if ufohit then
- ufohit = ufohit - 1
- if ufohit = 0 then
- ufohere = 0
- HideSprite expspr
- endif
- return
- endif
- endif
-
- ufox = ufox + ufospd
- if ufox > 320 then
- HideSprite ufospr
- ufohere = 0
- endif
-
- SetSprite ufospr to ufox,ufoy
-
- if bombon = 0 and random(1,100) = 2 then
- if ufoy < 130 then
- if ufox > 20 and ufox < 300 then
- bombon = 1
- bombx = ufox + 20
- bomby = ufoy
- bombyp = (hits / 8) + random(2,4)
- endif
- endif
- endif
-
- return
-
- Rem Update the UFO's bomb
- UpdateBomb:
-
- bomby = bomby + bombyp
- SetSprite bombspr to bombx,bomby
- if bomby > 230 then Goto GameOver
- return
-
- Rem this is the end...
- Rem A variety of techniques are being used in this
- Rem "Game Over" scene. One thing to notice is that
- Rem the 'x' position of the astronaut is also driving
- Rem other events. Also, 'snd' is used as a counter
- Rem to trigger a sound effect every tenth iteration of the
- Rem loop. Learning these methods can help you create
- Rem interesting scenes where a variety of things are
- Rem happening at once.
-
- GameOver:
- cls
- HideSprite ufospr
- HideSprite expspr
- for t = 1 to maxbullets
- HideSprite bulletspr(t)
- next t
-
- Background "earth"
- astro = LoadSprite("astro")
- x = -40
- TextColor 6
-
- snd = 0
- while x < 350
- x =x + 1
- SetSprite astro to x,80
- Rem part 1 ... a beam of devastation from above
- if x > 80 and x < 100 then
-
- if snd > 10 then
- snd = 0
- sound "lazer1"
- else
- snd = snd + 1
- endif
-
- diff = x - 80
- if diff > 11 then diff = 11
- color 6 + x
- line 160 - diff, 1 to 160 - diff,240
- line 160 + diff, 1 to 160 + diff,240
- endif
-
- Rem part 2 ... effect of said beam
- if x > 100 then
-
- if snd > 10 then
- snd = 0
- sound "exp_far"
- else
- snd = snd + 1
- endif
-
- diff = x - 100
- xcircle = random(1,320)
- ycircle = 240 - (diff*2)
- color random(6,21)
- FillCircle xcircle,ycircle,40-diff
- endif
- wend
- Color 21
- FillRect 0,0 to 320,240
- DrawText "@RED,HELVETICA,BOLD,50@Game Over" AT 25,10
- Banner "The Earth Is Toast"
- End
-
-
-